/**
 * @file       godemool/codec.h
 * @brief      file types.
 * @author     ben "boin" bonoeil
 * @date       2015-02
 */

/* Copyright (c) 2007-2015, ben "boin" bonoeil */

#ifndef GODEMOOL_FTYPES_H
#define GODEMOOL_FTYPES_H

#include "godemool/types.h"
#include <istream>

namespace boin {
  struct FInt8;
  struct FInt32;
  struct FFloat;
  struct FVector;
  typedef struct FVector FQangle;
}

/** File stored byte. */
struct boin::FInt8 {
  FInt8() {}
  FInt8(int8_t v) { *b = v; }
  uint8_t  b[1];
  operator uint8_t () const { return *b; }
  operator char * () { return (char*) b; }
};

/** File stored (little endian) 32bit integer. */
struct boin::FInt32 {
  FInt32() {}
  FInt32(int32_t v) { i = v; }
  FInt32(std::istream & is);
  void Read(std::istream & is);
  union { uint8_t  b[4]; uint32_t i; };
  operator uint32_t () const { return i; } ///< @todo portable conversion
  operator char * () { return (char*) b; }
};

/** File stored (little endian) 32bit IEEE754 floats. */
struct boin::FFloat {
  FFloat() {}
  FFloat(float v) { f = v; }
  FFloat(std::istream & is);
  void Read(std::istream & is);
  union { uint8_t b[4]; float f; };
  operator float() const { return f; } ///< @todo portable conversion
  operator char * () { return (char*) b; }
};

/** File 3D vectors. */
struct boin::FVector {
  FVector() {}
  FVector(std::istream & is);
  void Read(std::istream & is);
  FFloat x, y, z;
  operator char * () { return x; }
  operator boin::Vector() const { return boin::Vector(x,y,z); } ///< @todo portable conversion
};

#endif

/* Local Variables:  */
/* mode: c++         */
/* End:              */
